/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/17
*/
#ifndef __EDUI_CONTAINER_H__
#define __EDUI_CONTAINER_H__

#include "../controls/Control.h"

#include <vector>

EDUI_NAMESPACE_BEGIN

class ScrollBar;

class EDUI_API Container : public Control
{
    friend class IWindow;
protected:
    Container();
    virtual ~Container();
public:
	virtual void Release();
	static Container* GetInterface();
    static Container* ToContainer(Control* ctrl);
public:
    bool Add(Control* ctrl);
    bool AddAt(Control* ctrl, size_t index);
    Control* Get(const char* name);
    Control* GetByIndex(size_t index);
    void Remove(Control* ctrl);
    void Remove(const char* name);
    void RemoveByIndex(size_t index);
    void Clear();
    size_t Count();
public:
    ScrollBar* GetHScrollBar();
    ScrollBar* GetVScrollBar();
    bool LoadHScrollBar(const char* xmlstr);
    bool LoadVScrollBar(const char* xmlstr);
public:
    bool  SetInset(const Rect1* inset);
    Rect1 GetInset() const;
    void SetChildPadding(int paddingX, int paddingY);
    Size GetChildPadding() const;
    
    virtual void AutoLayout();
    virtual void SetAttribute(const char* name, const char* value);
    
    virtual Control* FindControl(const char* name);
    virtual Control* FindControlByTabID(int id);
    virtual Control* FindControlByPt(int x, int y, Uint32 flag = FIND_ALL);
    virtual bool ChildCanInvaldate(Control* child);
protected:
    virtual bool HandleMsg(Msg* msg);
    virtual void Render(IRender* render, const Rect* rc);

protected:
	typedef std::vector<Control*> ItemMap;
    ItemMap* m_items;

    Rect1 m_rcInset;
    Size m_childPadding;

    ScrollBar* m_hScrollBar;
    ScrollBar* m_vScrollBar;
};

EDUI_NAMESPACE_END

#endif
